package com.orion.controller;

import com.orion.domain.TestUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 * @date 2021/9/26
 */
@RestController
@RequestMapping("/client")
public class ClientController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/receiveCode")
    public String receiveCode(String code) {
        System.out.println("receive callback authorization code : " + code);
        return code;
    }

    @GetMapping("/receiveCode2")
    public String receiveCode() {
        return "/fefe";
    }

    @GetMapping("/getXx")
    public String getXx() {
        return restTemplate.getForObject("http://127.0.0.1:8548/myoauth/xx", String.class);
    }

    @GetMapping("/getUser")
    public TestUser getUser() {
        Map<String, Object> paramMap = new HashMap<>(2);
        paramMap.put("id", 4);
        TestUser testUser = restTemplate.getForObject("http://127.0.0.1:8548/myoauth/user", TestUser.class, paramMap);
        System.out.println(testUser.getName());
        return testUser;
    }

    @GetMapping("/getPostUser")
    public TestUser getPostUser() {
        Map<String, Object> paramMap = new HashMap<>(2);
        paramMap.put("id", 5);
        TestUser testUser = restTemplate.postForObject("http://127.0.0.1:8548/myoauth/postUser", paramMap, TestUser.class);
        System.out.println(testUser.getName());
        return testUser;
    }
}
